package cn.edu.bjut.homework.chapter7;

import java.awt.EventQueue;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;

public class FlowLayoutTester {
	private JFrame frm;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FlowLayoutTester window = new FlowLayoutTester();
					window.frm.setVisible(true);
					window.frm.pack(); // 调整窗口的大小，使其适应组件的大小和布局
					window.frm.setLocationRelativeTo(null); //让窗体居中显示
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public FlowLayoutTester() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frm = new JFrame();
		frm.setTitle("FlowLayout测试");
		frm.setBounds(100, 100, 450, 300);
		frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		FlowLayout flowLayout = new FlowLayout();
		flowLayout.setAlignment(FlowLayout.LEFT);
		frm.getContentPane().setLayout(flowLayout);
		
		for (int i = 1; i <= 8; i++) {
			frm.getContentPane().add(new JButton(String.valueOf("Button" + i)));
		}
	}
}